package com.singzi.leetcode.N2100;

import java.util.Arrays;

public class T2016 {
}
class Solution2016 {
    public int maximumDifference(int[] nums) {

        int n = nums.length;
        int []maxNums = new int[n];
        int []minNums = new int[n];
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if (nums[n - i - 1] > max) max = nums[n - i - 1];
            maxNums[n - i - 1] = max;
            if (nums[i] < min) min = nums[i];
            minNums[i] = min;
        }
        System.out.println(Arrays.toString(maxNums));
        System.out.println(Arrays.toString(minNums));
        max = 0;
        for (int i = 0; i < n; i++) {
            if(maxNums[i] - minNums[i] > max) max = maxNums[i] - minNums[i];
        }
        return max==0?-1:max;

    }
}